let login=[
    {
        title:'DDD之我见',
        digest:'DDD之我见',
        details:'DDD之我见',
        classify:'编程技术',
        author:'某大神',
        ptime:'2022-04-03',
    },
    {
        title:'66',
        digest:'66',
        details:'66',
        classify:'编程技术',
        author:'李四',
        ptime:'2022-04-03',
    },
    {
        title:'Linux用户创建的学习研究',
        digest:'Linux用户创建的学习研究',
        details:'Linux用户创建的学习研究',
        classify:'Linux',
        author:'某大神',
        ptime:'2022-04-03',
    },
]
//必要的引用
'use strict'
const Koa=require('koa');
const router=require('koa-router')();
const bodyParser=require('koa-bodyparser');
const cors=require('koa-cors');
const Sequelize=require('sequelize');
let login=require('./model/Login');
//连接数据库的突然忘了

//查找
router.get('/login',(ctx,next)=>{
    let keyword=ctx.reques.query.keyword || '';
    let arr=login;
    if(keyword){
        
    }

})
//查找指定id
router.get('/login/:id',(ctx,next)=>{
    let id=ctx.reques.query.id;
    let arr=login;
    if (id) {
        arr.forEach(item=>{
            ctx.body={
                code:1000,
                data:arr,
                msg:'成功！'
            }
        })
    }else{
        ctx.body={
            code:400,
            data:'',
            msg:'失败！'
        }
    }

})
//新增
router.post('/login',(ctx,next)=>{
    let id=ctx.reques.pramae.id;
    let arr=login;
    if (id) {
        arr.forEach(item=>{
            ctx.body={
                code:1000,
                data:arr,
                msg:'成功！'
            }
        })
    }else{
        ctx.body={
            code:400,
            data:'',
            msg:'失败！'
        }
    }
})
//修改
router.put('/login/:id',(ctx,next)=>{
    let id=ctx.reques.pramae.id;
    let obj=ctx.reques.body;
    if (obj.id) {
        arr.forEach(item=>{
            ctx.body={
                code:1000,
                data:arr,
                msg:'成功！'
            }
        })
    }else{
        ctx.body={
            code:400,
            data:'',
            msg:'失败！'
        }
    }

})
//删除
router.delete('/login/:id',(ctx,next)=>{
    let id=ctx.reques.pramae.id;
    let arr=login;
    if (id) {
        arr.forEach(item=>{
            ctx.body={
                code:1000,
                data:arr,
                msg:'成功！'
            }
        })
    }else{
        ctx.body={
            code:400,
            data:'',
            msg:'失败！'
        }
    }
})

//new一个Koa对象
let app=new Koa();

app.use(cors());
app.use(bodyParser());
app.use(router.routes());

let port=3000;
// app.listener(port);//?
console.log(`服务器运行在以下链接:http://localhost:${port}`);